#include "nyu_refcnt.h"

gpointer nyu_refcnt_ref(gpointer p)
{
    NyuRefcnt *self = p;

    if (self != NULL)
        ++self->count;

    return self;
}

void nyu_refcnt_unref(gpointer p)
{
    NyuRefcnt *self = p;

    if (self == NULL)
        return;

    --self->count;

    if (self->count > 0)
        return;

    if (self->destroy != NULL)
        self->destroy(p);

    nyu_refcnt_free(self);
}
